﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using RTSoft.Modules;
using RTSoft.SoureCode.Control.Login;
using RTSoft.SoureCode.Control.NhanVien;

namespace RTSoft.SoureCode.Entity
{
    public partial class frmDangNhap : DevExpress.XtraEditors.XtraForm
    {
        public frmDangNhap()
        {
            InitializeComponent();
        }
        String errConnect;
        String errSQL;

        private void simpleButton2_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btnLogin_Click(object sender, EventArgs e)
        {
            loginctrl ctrl = new loginctrl();
            int rs = ctrl.isValidate(ref errConnect,ref errSQL, txtUsername.Text, txtPassword.Text);
            if (rs != 0)
            {
                nhanvieninfo nv = new nhanvieninfo();
                nv = ctrl.getEmployee(ref errConnect, ref errSQL, txtUsername.Text);
                RTValidate.RTUser = nv.TEN_NV;
                RTValidate.RTJobTittle = nv.ID_NHOM;
                frmMain main = new frmMain();
                this.Hide();
                main.ShowDialog();
            }
            else
            {
                Library.ShowMessage("Kiểm tra mật khẩu!");
            }
            
        }

        private void txtUsername_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter) {
                btnLogin_Click(sender, e);
            }
        }

        private void frmDangNhap_Load(object sender, EventArgs e)
        {
            DevExpress.Skins.SkinManager.EnableFormSkins();            
        }
    }
}